package tech.jabari.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import tech.jabari.user.entity.User;
import tech.jabari.user.service.UserService;
import tech.jabari.user.service.impl.UserServiceImpl;
import tech.jabari.utils.PageBean;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UserListController  {

    @Autowired
    private UserService userService;

    @RequestMapping("/userList.action")
    @ResponseBody
    public PageBean<User> userList(@RequestParam("pageNo") String pageNoStr,
                                   @RequestParam("pageSize") String pageSizeStr,
                                   String username)
            throws ServletException, IOException {
        Integer pageNo = Integer.parseInt(pageNoStr);
        Integer pageSize = Integer.parseInt(pageSizeStr);
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("pageNo", pageNo);
        paramMap.put("pageSize", pageSize);
        paramMap.put("username", username);
        //将参数传给Service。
        PageBean pageBean = userService.selectAllUser(paramMap);
        //将结果展示给浏览器。
//        response.getWriter().write(result);
        return pageBean;
    }
}
